﻿using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Management.Automation;
using Microsoft.SharePoint;
using Microsoft.SharePoint.PowerShell;

using Microsoft.Office.Server.Search.Administration;
using Microsoft.Office.Server.Search.Cmdlet;

namespace Community.SharePoint.PowerShell
{
    /// <summary>
    /// SharePoint PowerShell Community Kit
    /// Remove-SPEnterpriseSearchQueryScopeDisplayGroup
    /// This cmdlet removes a scope display group given a site collection
    /// given a ScopeDisplayGroupPipeBind
    /// Example (Removes a scope display group called "New Display Group"): 
    /// $searchapp = Get-SPEnterpriseSearchServiceApplication "Search Service Application"
    /// $group = Get-SPEnterpriseSearchQueryScopeDisplayGroup -Name "New Scope Display Group" -url http://sp2010 -SearchApplication $searchapp
    /// Remove-SPEnterpriseSearchQueryScopeDisplayGroup -Identity $group
    /// Author: Corey Roth (coreyroth@gmail.com)
    /// Creation Date: 8/10/2010
    /// http://www.dotnetmafia.com
    /// </summary>
    [Cmdlet(VerbsCommon.Remove, "SPEnterpriseSearchQueryScopeDisplayGroup")]
    public class RemoveEnterpriseSearchQueryScopeDisplayGroup : SPRemoveCmdletBase<ScopeDisplayGroup>
    {
        [Parameter(Mandatory = true, ValueFromPipeline = true, Position = 0)]
        public ScopeDisplayGroupPipeBind Identity
        {
            get
            {
                return (ScopeDisplayGroupPipeBind)base.Fields["Identity"];
            }
            set
            {
                base.Fields["Identity"] = value;
            }
        }

        /// <summary>
        /// This seems to be the standard way of reading the underlying object from a 
        /// pipe bind.
        /// </summary>
        protected override void InternalValidate()
        {
            base.DataObject = this.Identity.Read();
            if (base.DataObject == null)
            {
                base.SkipProcessCurrentRecord();
            }
        }

        protected override void DeleteDataObject()
        {
            base.DataObject.Delete();
        }
    }
}
